package com.ruoyi.web.controller.subject;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.subject.domain.*;
import com.ruoyi.subject.service.ISpecialSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;



/**
 * @author 11975
 */

@Api(tags = "公开情报专题模块")
@RestController
@RequestMapping("/webs/subject")
public class SubjectController extends BaseController {

    @Autowired
    ISpecialSubjectService specialSubjectService;


    @ApiOperation("获取公开情报专题任务列表")
    @GetMapping("/list")
    public TableDataInfo getSubjectList(SubjectCatalog catalog) {
        startPage();
        List<SubjectCatalog> list = specialSubjectService.getSubjectList(catalog);
        return getDataTable(list);
    }

    @ApiOperation("新增公开情报专题任务列表")
    @PostMapping("/add")
    public AjaxResult addSubjectCatalog(@RequestBody SubjectCatalog catalog) {

        int row = specialSubjectService.addSubjectCatalog(catalog);
        return toAjax(row);
    }

    @ApiOperation("删除公开情报专题任务列表")
    @DeleteMapping("/del/{ids}")
    public AjaxResult delSubjectCatalog(@PathVariable Long[] ids) {
        int row = specialSubjectService.delSubjectCatalog(ids);
        return toAjax(row);
    }

    @ApiOperation("根据专题类型查询章节列表")
    @GetMapping("/list/chapter")
    public AjaxResult getSubjectChapterList(SubjectCatalog catalog) {
        SubjectChapterAndTarget subjectChapterList = specialSubjectService.getSubjectChapterList(catalog);
        return AjaxResult.success(subjectChapterList);
    }

    @ApiOperation("存储模板信息")
    @PostMapping("/template")
    public AjaxResult addSubjectTemplate(SubjectTemplate template) {
        int row = specialSubjectService.addSubjectTemplate(template);
        return toAjax(row);
    }

    @ApiOperation("删除模板信息")
    @DeleteMapping("/template/{ids}")
    public AjaxResult deleteSubjectTemplate(@PathVariable Long[] ids) {
        int row = specialSubjectService.deleteSubjectTemplate(ids);
        return toAjax(row);
    }

    @ApiOperation("查询模板下调用接口")
    @GetMapping("/report/{templateId}/{subjectId}")
    public AjaxResult getReportBaseInfo(@PathVariable Long templateId, @PathVariable Long subjectId) {

        return AjaxResult.success(specialSubjectService.getReportBaseInfo(templateId, subjectId));
    }


    @ApiOperation("获取主题目标列表（人物事件暂无）")
    @GetMapping(value = "/target")
    public AjaxResult getTargetList(@ApiParam(value = "1舰船 2飞机 3雷达 4导弹 5固定设施 6人物 7事件") Integer type)
    {
        List<Map<String,Object>> list = specialSubjectService.getTargetList(type);
        return AjaxResult.success(list);
    }

    @ApiOperation("获取专题下所有模板")
    @GetMapping(value = "/")
    public AjaxResult getTempleateList(@ApiParam(value = "1舰船 2飞机 3雷达 4导弹 5固定设施 6人物 7事件") Integer type)
    {
        List<SubjectTemplate> list = specialSubjectService.getTempleateList(type);
        return AjaxResult.success(list);
    }

    @ApiOperation("生成PDF文件")
    @PostMapping(value = "/pdf")
    public AjaxResult createPdf(@Validated @RequestBody CreatePdf createPdf)
    {
        return AjaxResult.success(specialSubjectService.createPdf(createPdf));
    }

    @ApiOperation("获取PDF路径")
    @GetMapping(value = "/pdfPath")
    public AjaxResult getPdfPath(@ApiParam(value = "专题ID") Integer subjectId)
    {
        return AjaxResult.success(specialSubjectService.getPdfPath(subjectId));
    }
}
